package com.it.executorService;

import java.util.concurrent.*;

/**
 * ClassName: ExecutorServiceDemo2
 * Description: 线程池创建Callable任务
 *
 * @Author: csx
 * @Create: 2025/5/8 - 9:10
 * @version: v1.0
 */
public class ExecutorServiceDemo2 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService pool = new ThreadPoolExecutor(3, 5,
                10, TimeUnit.SECONDS, new LinkedBlockingDeque<>(3),
                Executors.defaultThreadFactory(), new ThreadPoolExecutor.AbortPolicy());

        Callable<String> c1 = () -> {
            for (int i = 0; i < 5; i++) {
                System.out.println(Thread.currentThread().getName() + " 输出：" + i);
            }
            return Thread.currentThread().getName() + " 执行完毕！";
        };
        Future<String> submit = pool.submit(c1);
        Future<String> submit2 = pool.submit(c1);
        Future<String> submit3 = pool.submit(c1);
        System.out.println(submit.get());
        System.out.println(submit2.get());
        System.out.println(submit3.get());

//        pool.shutdown();
    }
}
